package com.demo.cloud.controller;

import com.demo.cloud.service.DemoService;
import com.demo.cloud.test.TestPropertyRefresh;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("demo-2")
@RefreshScope
public class DemoController {

    @Autowired
    private DemoService demoService;
    @Value("${cloud.demo}")
    private String name;

    @Autowired
    private TestPropertyRefresh test;

    @GetMapping("hello/{name}")
    public String hello(@PathVariable String name) {
        return demoService.hello(name);
    }

    @GetMapping("config")
    public String config() {
        return "config-server: " + name;
    }

    @GetMapping("getValue")
    @ResponseBody
    public String refreshValue() {
        return test.getValue();
    }

    @GetMapping("envValue")
    @ResponseBody
    public String getNowValue() {
        return test.getNowValue();
    }

}
